# 1. 导包
import jsonschema

# 2. 准备校验规则,
schema = {
    "type": "object",
    "properties": {
        "success": {"type": "boolean"},
        "code": {"type": "integer"},
        "message": {"pattern": "登录成功$"},
        "data": {"type": "object",
                 "properties": {
                     "name": {"const": "lily"},
                     "age": {"const": 20},
                 },
                 "required": ["name", "age"]
                 },
    },
    "required": ["success", "code", "message", "data"]

}
# 3. 准备待校验数据
json_data = {
    "success": True,
    "code": 9999,
    "message": "登录成功",
    "data": {
        "name": "lily",
        "age": 20,
        "sex": "女"
    },
    "luckyNumber": [6, 8, 9]
}

res = jsonschema.validate(instance=json_data, schema=schema)
print("校验完成",res)
